@extends('layouts.default')
@section('content')
<div class="row">
    <div class="col-md-12">
        <!-- general form elements -->
        <div class="card card-primary">
            <div class="card-header">
                @if(isset($banner))
                <h3 class="card-title">更新轮播</h3>
                @else
                <h3 class="card-title">新增轮播</h3>
                @endif
            </div>
            @include('layouts.error')
            <!-- /.card-header -->
            <!-- form start -->
            @if(isset($banner))
            <form role="form" method="post" enctype="multipart/form-data" action="{{url('admin/banner/update',[$banner->id])}}">
                {{ csrf_field() }}
                <div class="card-body">
                    <div class="form-group">
                        <label for="banner-title">标题</label>
                        <input type="text" name="title" class="form-control" id="banner-title" placeholder="请输入轮播标题" value="{{old('title',$banner->title)}}">
                    </div>

                    <div class="form-group">
                        <label for="banner-url">跳转链接</label>
                        <input type="text" name="url" class="form-control" id="banner-url" placeholder="填写跳转链接" value="{{old('url',$banner->url)}}">
                    </div>
                    <div class="form-group">
                        <label for="banner-url">排序</label>
                        <input onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" type="text" name="sort" class="form-control" id="banner-url" placeholder="输入整数" value="{{old('sort',$banner->sort)}}">
                    </div>
                    <div class="form-group">
                        <label for="banner-image">轮播图片</label><br>
                        <label for="file" class='btn btn-success col-md-2'>
                            <input type="file" name="image" id="file" class="inputfile" onchange="changepic(this)" style="opacity: 0;width: 5%" />
                            选择图片</label>
                        <img src="{{$banner->image}}" id="show" width="200">
                    </div>
                </div>
                <!-- /.card-body -->

                <div class="card-footer" >
                    <button type="submit" class="btn btn-primary " style="float: right">Submit</button>
                </div>
            </form>
            @else
            <form role="form" method="post" enctype="multipart/form-data" action="{{url('admin/banner/store')}}">
                {{ csrf_field() }}
                <div class="card-body">
                    <div class="form-group">
                        <label for="banner-title">标题</label>
                        <input type="text" name="title" class="form-control" id="banner-title" placeholder="请输入轮播标题" value="{{old('title')}}">
                    </div>

                    <div class="form-group">
                        <label for="banner-url">跳转链接</label>
                        <input type="text" name="url" class="form-control" id="banner-url" placeholder="填写跳转链接" value="{{old('url')}}">
                    </div>
                    <div class="form-group">
                        <label for="banner-url">排序</label>
                        <input onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" type="text" name="sort" class="form-control" id="banner-url" placeholder="输入整数" value="{{old('sort')}}">
                    </div>
                    <div class="form-group">
                        <label for="banner-image">轮播图片</label><br>
                        <label for="file" class='btn btn-success col-md-2'>
                            <input type="file" name="image" id="file" class="inputfile" onchange="changepic(this)" style="opacity: 0;width: 5%" />
                            选择图片</label>
                        <img src="" id="show" width="200">
                    </div>
                </div>
                <!-- /.card-body -->

                <div class="card-footer" >
                    <button type="submit" class="btn btn-primary " style="float: right">Submit</button>
                </div>
            </form>
            @endif

        </div>
        <!-- /.card -->
    </div>
</div>
@stop
@section('script')
    <script src="{{asset('admin-lte/plugins/jquery/jquery.min.js')}}"></script>
    <script>
        function changepic() {
            var reads= new FileReader();
            f=document.getElementById('file').files[0];
            reads.readAsDataURL(f);
            reads.onload=function (e) {
                document.getElementById('show').src=this.result;
            };
        }
    </script>
@stop